﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LCA.Community.DAL.Model;
using LCA.Community.DAL.Interfaces;

namespace LCA.Community.DAL
{
    /// <summary>
    /// The repository for hospitals implemented using Windows Azure
    /// </summary>
    public class HospitalsRepository : BaseRepository<Hospital>, IHospitalsRepository
    {
        #region Fields
        private IHospitalPatientsRepository _hospitalPatientsRepository; 
        #endregion

        public HospitalsRepository(IDataServiceContext<Hospital> dataServiceContext, IHospitalPatientsRepository hospitalsPatientsRepository)
            :base(dataServiceContext)
        {
            _hospitalPatientsRepository = hospitalsPatientsRepository;
        }

        /// <summary>
        /// Gets the hospital of a user.
        /// </summary>
        /// <param name="userID">The user ID.</param>
        /// <returns></returns>
        public Hospital GetHospitalOfUser(string userID)
        {
            return (from hp in _hospitalPatientsRepository.Entities
                    where hp.Patient == userID
                    select Get(hp.Hospital)).FirstOrDefault();
        }
    }
}
